package com.heima.controller;


import com.heima.mapper.PartnerMapper;
import com.heima.pojo.dto.PartnerDto;
import com.heima.pojo.dto.PartnerQueryParam;
import com.heima.pojo.domain.PageResult;
import com.heima.pojo.vo.PartnerVo;
import com.heima.service.PartnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user-service/partner")
public class PartnerController {

    @Autowired
    private PartnerService partnerService;
    @Autowired
    private PartnerMapper partnerMapper;

    /**
     * 获取合作商数量
     * @return
     */
    @GetMapping("/count")
    public Integer countPartner(){
        return partnerMapper.countPartner();
    }



    @GetMapping("/search")
    public PageResult search(PartnerQueryParam pqp){
        PageResult pageResult = partnerService.select(pqp);
        return pageResult;
    }

    @GetMapping("/{id}")
    public PartnerVo look(@PathVariable Integer id){
        PartnerVo partnerVo = partnerService.look(id);
        return partnerVo;
    }

    @PostMapping
    public Boolean add(@RequestBody PartnerDto partnerDto){
        Boolean res = partnerService.insert(partnerDto);
        return res;
    }

    @DeleteMapping("{id}")
    public Boolean del(@PathVariable Integer id){
        Boolean res = partnerService.delPartner(id);
        return res;
    }

    @PutMapping("{id}")
    public Boolean getPartnerService(@PathVariable Integer id, @RequestBody PartnerDto partnerDto){
        Boolean res = partnerService.update(id,partnerDto);
        return res;
    }

//    @PutMapping("/resetPwd/{id}")
//    public Boolean resetPwd(@PathVariable Integer id){
//        Boolean res = partnerService.updatePwd(id);
//        return res;
//    }
}
